package com.xinghou.platform.dao.main.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

import com.xinghou.platform.dao.bases.JdbcTemplate;
import com.xinghou.platform.dao.bases.database.CustomerContextHolder;
import com.xinghou.platform.dao.main.PhotoAlbumDAO;
import com.xinghou.platform.model.main.PhotoAlbum;
/**
 * @author liuwei.wen
 *
 */
@Service
public class PhotoAlbumDAOImpl  {/*
	@Resource
	private JdbcTemplate jdbcTemplate;

	@Override
	public PhotoAlbum getPhotoAlbumByalbumId(Integer albumId)
			throws DataAccessException {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		String sql = "select Album_id,User_id,NAME,Description,Privacy,Create_time from photo_album where Album_id = ?";
		PhotoAlbum photoAlbum = jdbcTemplate.queryForObject(sql, new Object[] { albumId }, new PhotoAlbumMapper());
		CustomerContextHolder.clearCustomerType();
		return photoAlbum;
	}

	@Override
	public int updatePhotoAlbum(PhotoAlbum photoAlbum)
			throws DataAccessException {
		StringBuffer strSQL = new StringBuffer(
				"UPDATE photo_album SET User_id=?,NAME=?,Description=?,Privacy=?,Create_time=? where Album_id=?"
				);
		Object[] params = {photoAlbum.getUserId(), photoAlbum.getName(), photoAlbum.getDescription(), photoAlbum.getPrivacy(), photoAlbum.getCreateTime(), 
				photoAlbum.getAlbumId()
		};
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_WRITE);
		int ret = jdbcTemplate.update(strSQL.toString(),params);
		CustomerContextHolder.clearCustomerType();
		return ret;
	}

	@Override
	public int savePhotoAlbum(PhotoAlbum photoAlbum)
			throws DataAccessException {
		StringBuffer strSQL = new StringBuffer(
				"INSERT INTO photo_album(User_id,NAME,Description,Privacy,Create_time)values(?,?,?,?,?)"
				);
		Object[] params = {photoAlbum.getUserId(), photoAlbum.getName(), photoAlbum.getDescription(), photoAlbum.getPrivacy(), photoAlbum.getCreateTime() 
		};
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_WRITE);
		int ret=jdbcTemplate.save(strSQL.toString(),params);
		CustomerContextHolder.clearCustomerType();
		return ret;
	}
	
	private static final class PhotoAlbumMapper implements RowMapper<PhotoAlbum> {
		public PhotoAlbum mapRow(ResultSet rs, int rowNum) throws SQLException {
			PhotoAlbum photoAlbum = new PhotoAlbum();
			photoAlbum.setAlbumId(rs.getInt("Album_id"));
			photoAlbum.setCreateTime(rs.getTimestamp("Create_time"));
			photoAlbum.setDescription(rs.getString("Description"));
			photoAlbum.setName(rs.getString("NAME"));
			photoAlbum.setPrivacy(rs.getShort("Privacy"));
			photoAlbum.setUserId(rs.getInt("User_id"));
			return photoAlbum;
		}
	}

	@Override
	public List<PhotoAlbum> getPhotoAlbumByUserId(Integer userId)
			throws DataAccessException {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		String sql = "select Album_id,User_id,NAME,Description,Privacy,Create_time from photo_album where User_id = ?";
		List<PhotoAlbum> photoAlbum = jdbcTemplate.query(sql, new Object[] { userId }, new PhotoAlbumMapper());
		CustomerContextHolder.clearCustomerType();
		return photoAlbum;
	}*/

}
